//
//  RequestPictureData.m
//  CarStop
//
//  Created by lanou3g on 15/7/17.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RequestPictureData.h"

@implementation RequestPictureData

- (void)requestPicture:(NSString *)picUrl reqSuccessBlockP:(reqPicSuccessBlock)reqSuccessBlockP reqErrorBlockP:(reqPicErrorBlock)reqErrorBlockP{

    self.reqSuccessBlockP = reqSuccessBlockP;
    self.reqErrorBlockP = reqErrorBlockP;
    NSURL *url = [NSURL URLWithString:[picUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (data) {
            self.reqSuccessBlockP(data);
        }
        if (connectionError) {
            self.reqErrorBlockP(connectionError);
        }
    }];

}

@end
